package com.qjdchina.sku.biz.impl;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qjdchina.commons.enums.IsDeleted;
import com.qjdchina.commons.result.Result;
import com.qjdchina.sku.biz.RoleBrandManager;
import com.qjdchina.sku.converter.RoleBrandConverter;
import com.qjdchina.sku.dao.mapper.RoleBrandMapper;
import com.qjdchina.sku.model.RoleBrand;
import com.qjdchina.sku.model.vo.RoleBrandVO;
import com.qjdchina.sku.service.enums.SkuResultCode;

/**
 * 角色品牌关联
 * @author shenpingfeng
 * 2017年2月15日
 */
@Service
public class RoleBrandManagerImpl implements RoleBrandManager {

	private static final Logger LOGGER = LoggerFactory.getLogger(RoleBrandManagerImpl.class);

	@Autowired
	private RoleBrandMapper roleBrandMapper;
	/**
	 * 创建角色品牌关联
	 * shenpingfeng
	 * 2017年2月15日
	 * @param roleBrandVO
	 * @return
	 */
	@Override
	public Result<String> create(RoleBrandVO roleBrandVO) {
		if(roleBrandVO == null){
			return new Result<String>(SkuResultCode.PARAMETER_NOT_EMPTY);
		}
		RoleBrand roleBrand = RoleBrandConverter.toRoleBrand(roleBrandVO);
		roleBrand.setGmtCreated(new Date());
		roleBrand.setGmtModified(new Date());
		roleBrand.setIsDeleted(IsDeleted.NO.getValue());
		int row = roleBrandMapper.insertSelective(roleBrand);
		if(row == 0){
			return new Result<String>(SkuResultCode.ADD_FAIL);
		}
		return new Result<String>(row+"");
	}	

}
